package com.x.mvp.utils;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/4/1.
 */


public class Combine<D> {
    List<D> allItem;
    int count;
    ArrayList<String> resault;
    public Combine(List<D> allItem) {
        this.allItem = allItem;
    }
    public List startCombine(int count) {
        resault = new ArrayList<>();
        ArrayList<Integer> combine = new ArrayList<>(count);
        for (int i = 0; i < count; i++) {
            combine.add(0);
        }
        int[] com = new int[count];
        for (int i = 0; i < count; i++) {
            com[i] = 0;
        }
        combine1(allItem.size(), count, com, count);
        return resault;
    }
    int getCombineCount(int count) {
        return 0;
    }
    private void combine1(int n, int m, int[] combine, int M) {
        for (int i = n; i >= m; i--) {
            combine[m - 1] = i - 1;
            if (m > 1)
                combine1(i - 1, m - 1, combine, M);
            else {
                String str = "";
                for (int j = M - 1; j >= 0; j--) {
                    str += allItem.get(combine[j]) + ",";
                }
                str = str.substring(0, str.length() - 1);
                resault.add(str);
            }
        }
    }
}